<?php
# !!!!!!!!!! DON'T MAKE ANY CHANGE IF YOU DON'T KNOW WHAT YOU'RE DOING !!!!!!!!!!
// --------------------------------------------------------------------------------------------------------------
// File Name              :	category.php
// Last Modification Time	:	2008-02-01 24:00
// Last Modified by       :	turker (turker.biz@gmail.com)
// list of modifications	:
//
//	- 2008-02-01 turker
//		* 24:00 file created.
//
// --------------------------------------------------------------------------------------------------------------
if (eregi("category.php",$_SERVER['PHP_SELF'])) {
	header ("Location:../index.php");
	exit;
}

$id=getID($CATEGORIES_TABLE);
if (!$id) {
  header ("Location:$SITE_URL/index.php?page=404");
	exit();
}

$page=findPage();
$start=($page-1)*$ITEMS_PER_CATEGORY;
?>

<!--div:icerik -->
    <div id="icerik">
<?php
// id, title, info, name, active, parent, order, lang, date
$active="and active='1'";
if (isAdmin()) $active='';
$q=$mysql->query("select title,`date`,`parent`,name,active from $CATEGORIES_TABLE where id='$id' and lang='$SITE_DEF_LANG' $active");
if ($mysql->numRows($q)==1) {
  $read=$mysql->fetch($q);
  $title=$prep->html($read['title']);
  $date=date('d/m/Y',$read['date']);
  $parent=$read['parent'];
  $cname=$read['name'];
  $cactive=$read['active'];
  if ($cactive=='1') $cactive='<img src="template/img/active.gif" title="Kategori Aktif" class="adminicon" />';
  else $cactive='<img src="template/img/notactive.gif" title="Kategori Aktif Değil" class="adminicon" />';

  # pagination start
  $pages=array();
  $query=$mysql->query("select count(id) as total from $ITEM_CATS_TABLE where cat_id='$id'");
  $total=$mysql->result($query,'total');
  $total_page=round($total/$ITEMS_PER_CATEGORY);
  for ($i=1;$i<=$total_page;$i++) {
    if ($i!=$page) {
      if (!$SITE_SEO) $pages[]="<a href=\"index.php?page=category&id=$id&p=$i\" title=\"".$_LANG['general']['page']." $i\">$i</a>";
      else $pages[]="<a href=\"$SITE_URL/category/$cname/$i\" title=\"".$_LANG['general']['page']." $i\">$i</a>";
    }
    else $pages[]=$i;
  }
  if (count($pages)>1) {
    $pages=implode(' | ',$pages);
    $pages='<div id="pagination">'.$pages.'</div><br />';
  }
  else $pages='';
  # pagination end

  echo "<p>".listCatParents($parent);
  if (isAdmin())
    echo '<div id="cat_edit_div" style="display:none;"><img src="template/img/loading.gif" title="Yükleniyor..." /></div>'
        .$cactive.' <img src="template/img/delete.gif" class="adminicon" title="Sil" id="cat_del" rel="'.$id.'" /> '
        .'<img src="template/img/edit.gif" class="adminicon" title="Düzenle" id="cat_edit" rel="'.$id.'" /> ';
  echo "<h1>$title</h1><h6>".$_LANG['page']['lupdate'].": $date</h6></p>";
  if (isAdmin()) {
    echo '<a href="index.php?page=add&what=subcat&cat_id='.$id.'" title="Alt Kategori Ekle">Alt Kategori Ekle</a>';
    echo '<a href="index.php?page=add&what=item&cat_id='.$id.'" title="Bu Kategoriye Yeni Ürün Ekle">Yeni Ürün Ekle</a>';
  }
  echo '<hr />';
  $subCats=listSubCats($id);
  if (!empty($subCats)) echo '<p><h3>'.$_LANG['category']['sucats'].'</h3>'.$subCats.'</p><hr />';
  echo '<p><h4>'.$_LANG['category']['items'].'</h4>';

  $items=listItems($id,$ITEMS_PER_CATEGORY,$start);
  if (!empty($items)) {
    echo $pages;
    $k=0;
    echo '<table cellpadding="5" cellspacing="5" width="100%" id="itemslist">';
    echo '<tr>';
    for ($i=0;$i<count($items);$i++) {
      // id, item, summary, info, name, home, new, lang, show_price, xml_code, image, date, brand_id, active, order, stock,
      // price, p_info, campaign, campaign_price, p_active, ex_name, exchange, e_active

      $item=$items[$i];
      $id=$item['id']; #*
      $title=$prep->html($item['item']); # urun adı*
      $summary=$prep->html($item['summary']); # urun özeti*
      $name=$item['name']; # urun permalink*
      $new=$item['new']; # yeni urun*
      $show_price=$item['show_price']; # fiyat goster*
      $item_active=$item['active']; # ürün aktif
      $image=$item['image']; # urun foto*
      $price=$item['price']; # fiyat*
      $info=$prep->html($item['p_info']); # fiyat açıklaması*
      $campaign=$item['campaign']; # kampanya*
      $campaign_price=$item['campaign_price']; # kampanya fiyatı*
      $item_price_active=$item['p_active']; # fiyat aktif *
      $ename=$prep->html($item['ex_name']); # kur adı*
      $exchange=$item['exchange']; # kur *
      $e_active=$item['e_active']; # kur aktif *

      // prepare item details
      $price="$price $ename +KDV";
      if (empty($image)||!file_exists('img/'.$image)) $image='template/img/noimg.png';
      else $image='img/'.$image;
      if ($new) $new='<img src="template/img/yeni.gif" />'; else $new='';
      if ($campaign_price>0&&$campaign) {
        $campaign='<img src="template/img/kampanya.gif" /><br />';
        $price="<s>$price</s> $campaign_price $ename +KDV";
      }
      else $campaign='';

      $item_link='<a href="index.php?page=item&id='.$id.'">'.$title.'</a>';
      if ($SITE_SEO) $item_link='<a href="'.$SITE_URL.'/item/'.$name.'">'.$title.'</a>';
      // -------------

      if (isAdmin()) {
        $show_price=1;
      }
      elseif (isLogged()) {
        if(!empty($item['price'])) {
          if ($show_price) {
            if ($item_price_active!='1'||$e_active!='1') {
              $price=$_LANG['brands']['oostock'];
              $info='';
              $campaign='';
            }
          }
          else $price=$_LANG['brands']['aprice'];
        }
        else $item_active=0;
      }
      else {
        if(!empty($item['price'])) {
          if ($SHOW_ITEM_PRICE==0) {
            $price='';
            $campaign='';
          }
          else {
            if ($show_price) {
              if ($item_price_active!='1'||$e_active!='1') {
                $price=$_LANG['brands']['oostock'];
                $info='';
                $campaign='';
              }
            }
            else $price=$_LANG['brands']['aprice'];
          }
        }
        else $item_active=0;
      }
      // -------------

      if (isAdmin()||$item_active=='1') {
        if (isAdmin()&&$item_active=='1') $item_active='<img src="template/img/active.gif" title="Ürün Aktif" />';
        elseif (isAdmin()&&$item_active=='0') $item_active='<img src="template/img/notactive.gif" title="Ürün Aktif Değil" />';
        else $item_active='';

        $price=trim($price);
        if ($price=='+KDV') $price=$_LANG['brands']['nhprice'];

        echo <<<html
        <td id="item-$id" class="item" width="50%">$new $item_link $item_active<br />
        <img src="$image" align="left" class="item-img" title="$title" />$summary<br /><br />
        $info<br />$campaign $price<br />
        </td>
html;
        if ($k%$ITEM_DISPLAY_COLUMN!=0) echo '</tr><tr>';
        $k++;
      }
    }
    echo '</tr></table>';
    echo $pages;
  }
  else echo $_LANG['category']['error1'];
  echo "</p>";
  if (goBack()) echo goBack();
}
else echo '<br />'.$_LANG['category']['error2'].'<br />';
?>
    </div>
<!--//div:icerik -->